<template>
	<!-- 商品-->
	<view class="">
		<image class="good-img" :src="item.img" mode=""></image>
	</view>
	<view class="good">
		<text class="good-title">{{item.name}}</text><br>
		<!-- 价钱 -->
		<view class="good-price">
			<text class="error"> 活动优惠 9折</text>
		</view>
		<!-- 浏览区域 -->
		<view class="good-static">
			<text class="good-static-text">月销：{{Math.floor(Math.random()*10000)}}</text>
			<text class="good-static-text">收藏：{{Math.floor(Math.random()*10000)}}</text>
			<text class="good-static-text">浏览：{{Math.floor(Math.random()*10000)}}</text>
		</view>
	</view>
	<view class="good-intro-box">
		<text class="good-intro-title">美食介绍</text><br>
		<text class="good-intro">{{item.intro}}</text>
	</view>
	<!-- 评价 -->
	<uni-section title="评价(1003) &nbsp;&nbsp;&nbsp;&nbsp; 好评率98.5%" type="line" titleFontSize="18px" padding />
	<view class="comment-box">
		<view class="comment" v-for="(item,index) in pinlun">
			<image class="comment-avatar" :src="item.img" mode=""></image>
			<view class="comment-right">
				<text class="comment-name">{{item.username}}</text>
				<text class="comment-content">{{item.intro}}</text>
				<text class="comment-date">时间:{{item.createdAt}}</text>
			</view>
		</view>
	</view>

</template>

<script setup>
	import {
		ref,
		computed
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		CONFIG
	} from '../../utils/config.js'
	// 状态库
	import {
		userStore
	} from '../../store/userStore';
	let store = userStore()


	let item = ref({})
	onLoad((data) => {
		getItemByid(data.id)
		getpinlun()
	})
	//根据index的id传的参数将信息传到详情页面
	async function getItemByid(id) {
		let data = {
			"objectId": id
		}
		let ed = encodeURI(JSON.stringify(data))
		let res = await uni.$get(CONFIG.leancloud_url + "/1.1/classes/ChinaPlayItem?where=" + ed)
		item.value = res.results[0]
		console.log(item.value)
		uni.setNavigationBarTitle({
			title: item.value.name
		})
		// 控制台输出经纬度
		console.log(store.currentPos)
		console.log(item.value.lat, item.value.lon)

	}
	// 评论
	let pinlun = ref([])
	async function getpinlun() {
		let res = await uni.$get(CONFIG.leancloud_url + "/1.1/classes/pinglunqu")
		pinlun.value = res.results
		console.log(pinlun.value)
	}
</script>


<style lang="scss">
	.good-img {
		width: 100%;
		height: 400px;
		display: block;
		margin: auto;
	}

	.good {
		width: 100%;
		height: 100%;

		.good-price {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin: 15px 0;

			.good-price1 {
				color: orange;
				font-size: 16px;
			}

			.good-price2 {
				color: #c3c3c3;
				text-decoration-line: line-through;
				font-size: 14px;
				margin: 0 10px;
			}

			.error {
				color: white;
				border: 1px solid red;
				border-radius: 5px;
				background-color: red;
			}
		}

		.good-static {
			display: flex;
			flex-direction: row;
			justify-content: space-between;

			.good-static-text {
				color: #c3c3c3;
				font-size: 12px;
			}
		}
	}

	.kilometer {
		width: 100%;
		font-size: 18px;
		font-weight: bold;
		border: 1px solid grey;
		border-radius: 10px;
		background-color: #c3c3c3;
	}

	.kilometer_span {
		border: 1px solid orange;
		border-radius: 10px;
		background-color: orange;
		color: red;
	}

	.good-intro-box {
		margin-top: 20px;
		height: 100%;
	}

	.good-title {
		font-size: 28px;
		color: black;
	}

	.good-intro-title {
		height: 100%;
		font-size: 45rpx;
		color: #fa436a;
	}

	.good-intro {
		margin-top: 20px;
		margin-left: 15px;
		font-size: 30rpx;
		color: #909399;
	}

	// 评价 
	.comment-box {
		border: 1px solid gray;

		.comment {
			display: flex;
			flex-direction: row;
			margin: 15px 0;


			.comment-avatar {
				width: 500px;
				height: 60px;
				border-radius: 50px;
				margin-right: 15px
			}

			.comment-right {
				flex-direction: column;
				justify-content: space-between;

				.comment-name {
					font-weight: bold;
				}

				.comment-content {
					margin: 5px 0;
					font-size: 12px;
					color: grey;
					text-indent: 1em;
					overflow: hidden;
					/* 设定行数 */
					-webkit-line-clamp: 5;
					/* 超出字符转换为........... */
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
				}

				.comment-date {
					color: #c9c9c9;
					font-size: 12px
				}
			}
		}
	}
</style>